package com.example.m_kartupay;

import java.io.InputStream;
import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ActorAdapter extends ArrayAdapter<Actors> {
	ArrayList<Actors> actorList;
	LayoutInflater vi;
	int Resource;
	ViewHolder holder;

	public ActorAdapter(Context context, int resource, ArrayList<Actors> objects) {
		super(context, resource, objects);
		vi = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		Resource = resource;
		actorList = objects;
	}
 
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// convert view = design
		View v = convertView;
		if (v == null) {
			holder = new ViewHolder();
			v = vi.inflate(Resource, null);
			//holder.imageview = (ImageView) v.findViewById(R.id.ivImage);
			holder.tvinvoice = (TextView) v.findViewById(R.id.tvinvoice);
			holder.tvorder_no = (TextView) v.findViewById(R.id.tvorder_no);
			holder.tvtype = (TextView) v.findViewById(R.id.tvtype);
			holder.tvsource= (TextView) v.findViewById(R.id.tvsource);
			holder.tvstatus = (TextView) v.findViewById(R.id.tvstatus);
			holder.tvpoints = (TextView) v.findViewById(R.id.tvpoints);
			holder.tvamount = (TextView) v.findViewById(R.id.tvamount);
			holder.tvtransaction_date = (TextView) v.findViewById(R.id.tvtransaction_date);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		//holder.imageview.setImageResource(R.drawable.ic_launcher);
		//new DownloadImageTask(holder.imageview).execute(actorList.get(position).getImage());
		holder.tvinvoice.setText(actorList.get(position).getinvoice());
		holder.tvorder_no.setText(actorList.get(position).getorder_no());
		holder.tvtype.setText(actorList.get(position).getsource());
		holder.tvsource.setText(actorList.get(position).gettype());
		holder.tvstatus.setText(actorList.get(position).getstatus());
		holder.tvpoints.setText(actorList.get(position).getpoints());
		holder.tvamount.setText(actorList.get(position).getamount());
		holder.tvtransaction_date.setText(actorList.get(position).gettransaction_date());
		return v;

	}

	static class ViewHolder {
		
		public TextView tvinvoice;
		public TextView tvorder_no;
		public TextView tvtype;
		public TextView tvsource;
		public TextView tvstatus;
		public TextView tvpoints;
		public TextView tvamount;
		public TextView tvtransaction_date;

	}

	private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
		ImageView bmImage;

		public DownloadImageTask(ImageView bmImage) {
			this.bmImage = bmImage;
		}

		protected Bitmap doInBackground(String... urls) {
			String urldisplay = urls[0];
			Bitmap mIcon11 = null;
			try {
				InputStream in = new java.net.URL(urldisplay).openStream();
				mIcon11 = BitmapFactory.decodeStream(in);
			} catch (Exception e) {
				Log.e("Error", e.getMessage());
				e.printStackTrace();
			}
			return mIcon11;
		}

		protected void onPostExecute(Bitmap result) {
			bmImage.setImageBitmap(result);
		}

	}
}